package com.wise.service.cms.content.applicationcolumns;

import com.wise.entities.content.ApplicationColumn;
import com.wise.framework.dao.SqlSelect;
import com.wise.framework.daomodel.DaoPageList;
import com.wise.framework.restful.PageResultList;
import com.wise.summer.v1.cms.content.applicationcolumns.ListApplicationColumns;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

import java.util.Objects;

/**
 * @author hejiawei
 * @date 2020/10/27 11:17
 */
@Service
@SummerService
public class ListApplicationColumnsService implements SummerServiceBean<ListApplicationColumns> {
    @Override
    public void sum(ListApplicationColumns model) {
        SqlSelect sql = SqlSelect.selec("*")
                .fromClassName(ApplicationColumn.class)
                .like(!StringUtils.isEmpty(model.getColumnName()), ApplicationColumn._columnName, "%" + model.getColumnName() + "%")
                .eq(!Objects.isNull(model.getShowState()), ApplicationColumn._showState, model.getShowState())
                .eqLang(ApplicationColumn._lang)
                .order_by(ApplicationColumn._sort)
                .order_by(ApplicationColumn._id + " desc");

        PageResultList<ApplicationColumn> applicationColumnPageResultList = DaoPageList.s(ApplicationColumn.class, sql, model.getStart(), model.getLimit());

        model.setSummerResult(applicationColumnPageResultList);

    }
}
